package com.mvm.store.web.action;

import java.util.List;

import com.mvm.store.domain.obj.Client;
import com.mvm.store.service.base.AbstractService;
import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.Preparable;

public class ClientAction extends ActionSupport implements Preparable {

	private AbstractService<Client, Integer> service;
	private List<Client> clients;
	private Client client;
	private Integer id;

	public void prepare() throws Exception {
		if (id != null)
			client = service.find(id);
	}

	public String execute() {
		this.clients = service.findAll();
		return Action.SUCCESS;
	}

	public String save() {
		this.service.save(client);
		this.client = new Client();
		return execute();
	}

	public String remove() {
		service.remove(id);
		return execute();
	}

	public List<Client> getClients() {
		return clients;
	}

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public Client getClient() {
		return client;
	}

	public void setClient(Client client) {
		this.client = client;
	}
}
